Skip to content

fix: delegate execution and tab completion of ignored commands to original plugins#3

Open
NoltoxGit wants to merge 5 commits into
BetterGUI-MC:masterfrom
HeavenCube:fix
Open

fix: delegate execution and tab completion of ignored commands to original plugins#3
NoltoxGit wants to merge 5 commits into
BetterGUI-MC:masterfrom
HeavenCube:fix

Conversation

@NoltoxGit

@NoltoxGit NoltoxGit commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

This pull request resolves a conflict where BetterGUI shadows command labels from other plugins (such as LMBishop's Quests plugin aliases /q, /quest, and /quests) and breaks both their command execution and native tab completion.

The Bug & Root Cause:

BetterGUI's MenuCommandManager registers dynamic menu commands in Bukkit's SimpleCommandMap during server startup. For plugins that declare aliases:

  1. BetterGUI registers separate command objects for those aliases, which overwrites the original plugin's alias entries in Bukkit's map.
  2. Even when this addon returned early in PlayerCommandPreprocessEvent, the event was not cancelled, leading Bukkit to execute the command currently residing in the map (BetterGUI's menu command, opening the menu).
  3. Tab completion for these overridden commands is also intercepted by BetterGUI's dynamic commands, returning an empty list.

Solution:

This PR implements a non-intrusive, single-file bug fix inside CommandListener.java:

  1. Double Interception:
    • Listens to both PlayerCommandPreprocessEvent (for execution) and TabCompleteEvent (for autocompletion).
  2. Command Resolution (findAlternativeCommand):
    • Performs a best-effort reflective lookup in Bukkit's command map (knownCommands) to find the shadowed original command (e.g., quests:q or quests:quest registered with the plugin namespace).
    • If the active command is not a BetterGUI menu command, it is ignored and Bukkit handles it naturally.
  3. Selective Cancellation & Overriding:
    • Execution: The event is cancelled and the original command is executed manually only if a shadowed native command was successfully resolved.
    • Tab completion: Suggestions are overwritten using event.setCompletions(...) only if a shadowed native command was resolved.

This approach ensures compatibility with Bukkit/Spigot/Paper from 1.9 up to modern versions, keeping the addon extremely simple and cohesive.

@SuppressWarnings("unchecked")
private Map<String, Command> getKnownCommands() {
try {
Field field = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants